﻿/*
 * 
 * TEST = OK
*/
Library.Util.Event = function (event) {    
    if (navigator.appName == "Netscape")
        return event;
    if (navigator.appName == "Microsoft Internet Explorer")
        return window.event;
    return event;
};

Library.Util.SrcElement = function (event) {
    if (event == null) 
        event = window.event;
    return Library.Util.Event(event).srcElement ? Library.Util.Event(event).srcElement : Library.Util.Event(event).target;
}

/*
* 
* TEST = OK
*/
Library.Util.Return = function(event, bool) {
    var e = Library.Util.Event(event);
    if (!bool) {
        if (e.stopPropagation) {
            e.stopPropagation();
            e.preventDefault();
        } else {
            e.returnValue = false;
            e.cancel = true;
        }
    } else {
        if (!e.stopPropagation) {
            e.returnValue = true;
            e.cancel = false;
        }
    }
    return bool;
};

/*
* 
* TEST = OK
*/
Library.Util.ReplaceAll = function(value, find, replace) {
    if (value == null || value == "")
        return "";
    do {
        value = value.replace(find, replace);
    } while (value.indexOf(find) != -1)
    return value;
};

/*
* 
* TEST = OK
*/
Library.Util.Count = function(value, find) {
    var c = 0;
    if (value == null || value == "" || value.indexOf(find) == -1)
        return 0;
    do {
        value = value.replace(find, "");
        c++;
    } while (value.indexOf(find) != -1)
    return c;
};

/*
* 
* TEST = OK
*/
Library.Util.SayiFormatla = function (sayi) {
    sayi = sayi + "";
    if (sayi.indexOf(",") != -1)
        return Library.Util.Basamakla(sayi.split(",")[0]) + "," + (sayi.split(",")[1] || "");
    return Library.Util.Basamakla(sayi);
};

/*
* 
* TEST = OK
*/
Library.Util.Basamakla = function (tutar) {    
    tutar = Library.Util.ReplaceAll(tutar, ".", "");
    var ttr = "";
    for (var i = 0; i < tutar.length; i++) {
        if (i != 0 && i % 3 == 0)
            ttr += "." + tutar.substr(tutar.length - i - 1, 1);
        else
            ttr += tutar.substr(tutar.length - i - 1, 1);
    }
    return ttr.split("").reverse().join("");    
};

Library.Util.Sleep = function (milliSeconds) {           
    var startTime = new Date().getTime();
    while (new Date().getTime() < startTime + milliSeconds);     
};